<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: Adminis
  Date: 2025/3/19
  Time: 11:24
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>角色管理</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/admin/css/bootstrap.min.css">
	<script src="${pageContext.request.contextPath}/admin/js/jquery-2.1.0.min.js"></script>
	<script src="${pageContext.request.contextPath}/admin/js/bootstrap.min.js"></script>
    <style>

       .cus-container{
           width: 1368px;
       }
       #user-add .modal-content{
       	padding: 0 20px 20px;	
       }
       #user-edit .modal-content{
       	padding: 0 20px 20px;	
       }
	   #user-list td{
		vertical-align: middle;
	   }
       b{
           color: red;
       }
       
    </style>
</head>
<body>
	
    <div class="container cus-container">
        <!-- <h3 class="text-center">用户信息列表</h3> -->

        <div>
            <!-- 搜索框div -->
            <div id="search-user" style="float: left; margin: 10px 0px;">
                <form class="form-inline" action="${pageContext.request.contextPath}/acl_role/selectAcl_roles" method="post">
                    <div class="form-group">
                        <label for="role_name">角色名称</label>
                        <input type="text" name="role_name" value="${role_name}" class="form-control" id="role_name" >
                    </div>
                   
                    <button type="submit" class="btn btn-default" >查询</button>
                    <button type="button" class="btn btn-default" >清空</button>
                </form>    
            </div>
            
            <!-- 添加、删除的按钮 -->
            <div style="float: right;margin: 10px 0px;">
                <a class="btn btn-primary" href="${pageContext.request.contextPath}/acl_role/toAddAcl_role">添加角色</a>
                <a class="btn btn-primary" onclick="dels()">删除选中</a>

            </div>
        </div>

      
       <table class="table table-bordered clearfix" id="user-list">
        <thead>
        	<tr class="bg-primary">
	            <th><input type="checkbox" id="firstCb"></th>
	            <th>角色序号</th>
	            <th>角色名称</th>
                <th>角色备注</th>
                <th>是否删除</th>
	            <th>操作</th> 
	        </tr> 
        </thead> 
        <tbody>
        <c:forEach items="${pageInfo.list}" var="acl_role">
            <tr class="active">
                <td><input type="checkbox" class="cb" value="${acl_role.role_id}"></td>
                <td>${acl_role.role_id}</td>
                <td>${acl_role.role_name}</td>
                <td>${acl_role.remark}</td>
                <td>${acl_role.is_deleted==0?"否":"是"}</td>
                <td>
                    <a class="btn btn-default btn-sm" href="${pageContext.request.contextPath}/acl_role/toUpdateAcl_role?role_id=${acl_role.role_id}">修改</a>
                    <a class="btn btn-default btn-sm" href="${pageContext.request.contextPath}/acl_role/softDeleteAcl_role?role_id=${acl_role.role_id}">删除</a>
                    <a class="btn btn-default btn-sm" href="${pageContext.request.contextPath}/acl_role/selectAcl_permissions?role_id=${acl_role.role_id}">分配权限</a>
                </td>
            </tr>
        </c:forEach>
        </tbody>
      </table>

        <%--前五后四--%>

        <c:if test="${pageInfo.pages>=10}">
            <c:set var="begin" value="1"></c:set>
            <c:set var="end" value="10"></c:set>
        <c:if test="${pageInfo.pageNum>5}">
            <c:set var="begin" value="${pageInfo.pageNum-4}"></c:set>
            <c:set var="end" value="${pageInfo.pageNum+5}"></c:set>
        </c:if>
        <c:if test="${pageInfo.pageNum+5>pageInfo.pages}">
            <c:set var="begin" value="${pageInfo.pages-9}"></c:set>
            <c:set var="end" value="${pageInfo.pages}"></c:set>
        </c:if>
        </c:if>

        <c:if test="${pageInfo.pages<10}">
            <c:set var="begin" value="1"></c:set>
            <c:set var="end" value="${pageInfo.pages}"></c:set>
        </c:if>

        <!-- 分页导航 -->
        <div>
            <nav style="text-align: center">
                <ul class="pagination">

                    <li>
                        <a href="${pageContext.request.contextPath}/acl_role/selectAcl_roles?currentPage=1&role_name=${role_name}">首页</a>
                    </li>

                    <li>
                        <a href="${pageContext.request.contextPath}/acl_role/selectAcl_roles?currentPage=${pageInfo.prePage}&role_name=${role_name}">&laquo;</a>
                    </li>

                    <c:forEach begin="${begin}" end="${end}" var="page">
                        <li ${page eq pageInfo.pageNum?"class='active'":''}>
                            <a href="${pageContext.request.contextPath}/acl_role/selectAcl_roles?currentPage=${page}&role_name=${role_name}">${page}</a>
                        </li>
                    </c:forEach>

                    <li>
                        <a href="${pageContext.request.contextPath}/acl_role/selectAcl_roles?currentPage=${pageInfo.nextPage}&role_name=${role_name}">&raquo;</a>
                    </li>

                    <li>
                        <a href="${pageContext.request.contextPath}/acl_role/selectAcl_roles?currentPage=${pageInfo.pages}&role_name=${role_name}">尾页</a>
                    </li>

                </ul>
            </nav>
            <div style="float: right;">
                <span>当前第<b>${pageInfo.pageNum}</b>页 共<b>${pageInfo.pages}</b>页 共<b>${pageInfo.total}</b>条数据</span>
            </div>
        </div>
     
    
</body>
</html>
<script>
    function dels() {
        let checkeds = $("input[class='cb']:checked");
        let roleIds = "";
        for (let i = 0; i < checkeds.length; i++){
            console.log(checkeds[i].value)
            roleIds += checkeds[i].value + ",";
        }
        if (roleIds.length > 0){
            if (confirm("确定删除吗？")){
                window.location.href = "${pageContext.request.contextPath}/acl_role/deleteAcl_roles?role_ids=" + roleIds;
            }
        }

    }

</script>